package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    void delete(List<Long> ids);
@Select("select * from dish where id = #{id}")
Dish getById(Long id);

    void updateDish(Dish dish);
@Select("select d.*,c.name as category_name from dish d left join category c on d.category_id = c.id where d.id = #{id}")
    DishVO getByIdvo(Long id);
@Insert("insert into dish (name, category_id, price, image, description, status, create_time, update_time, create_user, update_user) VALUES " +
        "(#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void insert(Dish dish);
@Select("select * from dish where category_id = #{categoryId} and status = 1")
    List<Dish> list(Dish dish);
@Update("update dish set status = #{status} where id = #{id}")
    void update(Dish dish);
    /**
     * 动态条件查询菜品
     * @param dish
     * @return
     */
    List<Dish> listByCategoryId(Dish dish);

    Integer countByMap(Map map);
}
